<?php

namespace App\Exports\Pay;

use App\Exports\Export;

class TransferExport extends Export
{

    /**
     * 映射标题行
     *
     * @return array
     */
    protected function headings(): array
    {
        return trans('view.pay.order.transfer.headings');
    }

    /**
     * 映射数据行
     *
     * @param \Illuminate\Database\Eloquent\Model $item
     * @return array
     */
    protected function map($item): array
    {
        return [
            $item->sn,
            $item->plat_sn,
            $item->uid,
            $item->org->name ?? $item->plat_code,
            $item->account_id,
            $item->currency,
            $item->amount,
            $item->balance_start,
            $item->balance_end,
            $this->statusList[$item->status] ?? $item->status,
            $this->transferTypeList[$item->transfer_type] ?? $item->transfer_type,
            timestamp_to_datetime($item->created),
            timestamp_to_datetime($item->updated),
            $item->usd['amount'] ?? null,
            $item->usd['balance_start'] ?? null,
            $item->usd['balance_end'] ?? null,
        ];
    }

    /**
     * 类型
     *
     * @var array
     */
    protected $transferTypeList;

    /**
     * 状态
     *
     * @var array
     */
    protected $statusList;

    /**
     * 初始化操作
     */
    protected function init()
    {
        // 类型
        $this->transferTypeList = trans('view.pay.order.transfer.transferTypeList');

        // 状态
        $this->statusList = trans('view.pay.order.transfer.statusList');

        // 文件名称
        $this->filename = trans('view.pay.order.transfer.filename');
    }
}
